package com.xxcxcxcx.xc_moremob.common.skills;

import com.xxcxcxcx.xc_moremob.common.entities.monster.realization.SkillBasicEntity;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.Goal;

import javax.annotation.Nullable;
//法术基类
public abstract class UseskillGoal extends Goal {
    protected int attackWarmupDelay;
    protected SkillBasicEntity mob;
    protected int nextAttackTickCount;
    protected int CastWarmupTime;
    protected int CastingTime;
    protected int CastingIntervalTime;
    public UseskillGoal(SkillBasicEntity mo){
        mob=mo;
        setCastWarmupTime(20);
        setCastingTime(30);
        setCastingInterval(30);
    }
    public UseskillGoal(SkillBasicEntity mo,int CastWarmup,int Casting,int CastingInterval){
        mob=mo;
        setCastWarmupTime(CastWarmup);
        setCastingTime(Casting);
        setCastingInterval(CastingInterval);
    }
    public boolean canUse() {
        LivingEntity livingentity = mob.getTarget();
        if (livingentity != null && livingentity.isAlive()) {
            if (mob.isCastingSpell()) {
                return false;
            } else {
                return mob.tickCount >= this.nextAttackTickCount;
            }
        } else {
            return false;
        }
    }
    public boolean canContinueToUse() {
        LivingEntity livingentity = mob.getTarget();
        return livingentity != null && livingentity.isAlive() && this.attackWarmupDelay > 0;
    }
    public void start() {
        this.attackWarmupDelay = this.adjustedTickDelay(this.getCastWarmupTime());
        mob.spellCastingTickCount = this.getCastingTime();
        this.nextAttackTickCount = mob.tickCount + this.getCastingInterval();
        SoundEvent soundevent = this.getSpellPrepareSound();
        if (soundevent != null) {
            mob.playSound(soundevent, 1.0F, 1.0F);
        }
        mob.setIsCastingSpell(this.getSpell());
    }
    public void tick() {
        --this.attackWarmupDelay;
        if (this.attackWarmupDelay == 0) {
            this.performSpellCasting();
            mob.playSound(mob.getCastingSoundEvent(), 1.0F, 1.0F);
        }
    }
    //生物施法函数
    protected abstract void performSpellCasting();
    //法术预热（动画）时间
    protected int getCastWarmupTime() {
        return CastWarmupTime;
    }
    protected void setCastWarmupTime(int a) {
        CastWarmupTime=a;
    }
    //生物施法冷却时间
    protected int getCastingTime(){
        return CastingTime;
    }
    protected void setCastingTime(int a){
        CastingTime = a;
    }
    //法术冷却时间
    protected int getCastingInterval(){
        return CastingIntervalTime;
    }
    protected void setCastingInterval(int a){
        CastingIntervalTime = a;
    }
    //生物施法声音
    @Nullable
    protected abstract SoundEvent getSpellPrepareSound();
    //生物施法数据
    protected abstract Currentskills getSpell();
}